﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Globalization;

namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// backInfo.xaml 的交互逻辑
    /// </summary>
    public partial class backInfo : Page
    {
        public backInfo()
        {
            InitializeComponent();
        }
        string strCon = Properties.Resources.strCON;
        string stuNum;

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            int firstRadio = 0; ;
            if(fny.IsChecked==true)
            {
                firstRadio = 1;
            }
            else if(fnn.IsChecked==true)
            {
                firstRadio = 0;
            }
            int secondRadio = 0; ;
            if (sny.IsChecked == true)
            {
                secondRadio = 1;
            }else if(snn.IsChecked==true)
            {
                secondRadio = 0;
            }
            int thirdRadio = 0;
            if (tny.IsChecked == true)
            {
                thirdRadio = 1;
            }else if (tnn.IsChecked == true)
            {
                thirdRadio = 0;
            }
            SqlCommand cmd = new SqlCommand("insert into backInfo(stunum,nowaddr,detailaddr,arrivetime,arriveplace,houseplace,housenum,whigh,wme,wagree) values(@id,@naddr,@daddr,@arrt,@arrp,@houp,@houn,@whi,@wme,@wagr)", con);
            cmd.Parameters.Add("@id", SqlDbType.Int, 10).Value = stuNum;
            cmd.Parameters.Add("@naddr", SqlDbType.VarChar, 50).Value = textPlace.Text;
            cmd.Parameters.Add("@daddr", SqlDbType.VarChar, 50).Value = textDetail.Text;
            cmd.Parameters.Add("@arrt", SqlDbType.VarChar, 50).Value = textDate.Text;
            cmd.Parameters.Add("@arrp", SqlDbType.VarChar, 50).Value = textAddress.Text;
            cmd.Parameters.Add("@houp", SqlDbType.VarChar, 50).Value = textHouse.Text;
            cmd.Parameters.Add("@houn", SqlDbType.VarChar, 50).Value = textNum.Text;
            cmd.Parameters.Add("@whi", SqlDbType.Int, 10).Value = firstRadio;
            cmd.Parameters.Add("@wme", SqlDbType.Int, 10).Value = secondRadio;
            cmd.Parameters.Add("@wagr", SqlDbType.Int, 10).Value = thirdRadio;
            cmd.ExecuteNonQuery();
            MessageBox.Show("填写完成");
            con.Close();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from studentInfo where studentStatus=@num", con);
            cmd.Parameters.Add("@num", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);
            //DataTable dt = new DataTable();
            DataSet dataset = new DataSet();
            read.Fill(dataset);
            DataTable table = dataset.Tables[0];
            DataRowCollection rows = table.Rows;
            DataRow row = rows[0];
            stuNum = row["studentNumber"].ToString();
        }
    }

    public class timeConver1 : IValueConverter
    {
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return DependencyProperty.UnsetValue;
            DateTime dt = (DateTime)value;
            return dt.ToString("yyyy年MM月dd日");
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
